package org.lightweightimageviewer.liv;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.File;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: Steven Boscarine
 * Date: Dec 19, 2007
 * Time: 4:53:03 PM
 * This is a utility class to retrieve sample images from local filesystem in unit tests.
 */
public class UnitTestUtil {
    public static File getSmallSample(){
        return getFromClasspath("classpath:/smallSample/start.jpg");
    }
    public static File getLargeSample(){
        return getFromClasspath("classpath:/largeSample/start.jpg");
    }
    private static  File getFromClasspath(String filename){
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        try {
            File file = context.getResource(filename).getFile();
            if(!file.exists()){
                throw new RuntimeException("File does not exist.  There is an error with the unit test config.");
            }
            return file;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
